//
// Created by hay boy on 2022/6/27.
//

#ifndef ALGORITHMS_TOWERSOFHANOI_H
#define ALGORITHMS_TOWERSOFHANOI_H
#include <iostream>
using namespace std;
void towersOfHanoi(int n,int x,int y,int z);
void moveAndShow(int,int,int,int);
void towersOfHanoi(int n);
void showState();
void towersOfHanoi(int n,int x,int y,int z){
    if(n>0){
        towersOfHanoi(n-1,x,z,y);
        cout<<"Move top disk from tower "<<x<<" to top of tower "<<y<<endl;
        towersOfHanoi(n-1,z,y,x);
    }
}
ArrayStack<int> tower[4];
void moveAndShow(int n, int x, int y, int z) {
    if(n>0){
        moveAndShow(n-1,x,z,y);
        int d = tower[x].top();
        tower[x].pop();
        tower[y].push(d);
        showState();
        moveAndShow(n-1,z,y,x);
    }
}

void towersOfHanoi(int n) {
    for(int d = n;d>0;d--){
        tower[1].push(d);
    }
    moveAndShow(n,1,2,3);
}

void showState() {
    cout<<"tower1 "<<tower[1]<<" tower2 "<<tower[2]<<"  tower3 "<<tower[3]<<endl;
}

#endif //ALGORITHMS_TOWERSOFHANOI_H
